import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

const store=new Vuex.Store({
  state:{
    // user:{
    //   id:'',
    //   username:'',
    //   sex:'',
    //   introduction:''
    // },
    // isLogin:false,
    user:JSON.parse(localStorage.getItem('user')) || {id:'',username:'',sex:'',introduction:''},
    isLogin:JSON.parse(localStorage.getItem('isLogin')),
    showUserDialog:false,
  },
  mutations: {
    //更新用户信息
    userLogin(state, user) {
      localStorage.setItem('user',JSON.stringify(user))
      state.user = user;
      if(user.id){
        state.isLogin=true;
        localStorage.setItem('isLogin',true)
      }else{
        state.isLogin=false;
      }
    },
    //处理弹出框
    handleDialog(state,val){
      state.showUserDialog = val;
      console.clear();
      console.log(state);
    }
  }
})

export default store;